package com.jh.netty.instruction.datapacket;

import com.jh.netty.instruction.DataPacket;
import lombok.Data;

/**
 * 取点状态  返回值解析
 *
 * 文档：七. 指令详细说明
 *
 * 5.取点状态
 *
 * @see DataPacket#CMD_GET_DOT_STATUS
 *
 * TX(指令): 52 52 01 01 00 01 40 F0 62
 * 回应点：01010101010101010101010104040404
 * 回应点状态表格式 16 byte
 */
@Data
public class CmdGetDotStatus {
    /**
     * 自动状态取值（按钮、门磁）OFF状态
     */
    public static final String STATUS_Automatic_OFF = "01";
    /**
     * 自动状态取值（按钮、门磁）ON状态
     */
    public static final String STATUS_Automatic_ON = "02";
    /**
     * 休眠状态
     */
    public static final String STATUS_Automatic_Door_Dormancy = "01";
    /**
     * 锁常开状态
     */
    public static final String STATUS_Automatic_Door_Lock_Open = "02";

    /**
     * 安全状态
     */
    public static final String STATUS_Automatic_Door_Security = "03";

    /**
     * 密码状态
     */
    public static final String STATUS_Automatic_Door_Pwd = "04";

    /**
     * APB安全状态
     */
    public static final String STATUS_Automatic_Door_APB_Security = "05";

    /**
     * APB密码状态
     */
    public static final String STATUS_Automatic_Door_APB_Pwd = "06";

    /**
     * 如果状态字节的高位=1，表示是手动态 按钮、门磁 OFF
     * 手动状态取值
     */
    public static final String STATUS_Manual_OFF = "81";

    /**
     * 如果状态字节的高位=1，表示是手动态 按钮、门磁 ON
     * 手动状态取值
     */
    public static final String STATUS_Manual_ON = "82";

    /**
     * 休眠状态
     */
    public static final String STATUS_Manual_Door_Dormancy = "81";
    /**
     * 锁常开状态
     */
    public static final String STATUS_Manual_Door_Lock_Open = "82";

    /**
     * 安全状态
     */
    public static final String STATUS_Manual_Door_Security = "83";

    /**
     * 密码状态
     */
    public static final String STATUS_Manual_Door_Pwd = "84";

    /**
     * APB安全状态
     */
    public static final String STATUS_Manual_Door_APB_Security = "85";

    /**
     * APB密码状态
     */
    public static final String STATUS_Manual_Door_APB_Pwd = "86";

    /**
     * 按钮1
     * 0=UNKNOW; 1=OFF; 2=ON;
     * <p>
     * 点地址（16）
     */
    private String btn1;
    /**
     * 门磁1
     * 0=UNKNOW; 1=OFF; 2=ON;
     * 点地址（17）
     */
    private String sensor1;

    private String btn2;

    private String sensor2;

    private String btn3;

    private String sensor3;

    private String btn4;

    private String sensor4;

    /**
     * 门锁1
     * :0=UNKNOW; 1=OFF; 2=ON;
     */
    private String lock1;

    private String lock2;

    private String lock3;

    private String lock4;

    /**
     * 0=UNKNOW;1=休眠状态;2=锁常开状态;3=安全状态;4=密码状态;5=APB 安全状态;6=APB 密码状态
     */
    private String door1;

    private String door2;

    private String door3;

    private String door4;

    /**
     * 根据数据包解析
     */
    public static CmdGetDotStatus parse(DataPacket dp) {
        return parse(dp.getDataCodeText());
    }

    public static CmdGetDotStatus parse(String dct) {
        CmdGetDotStatus cgds = new CmdGetDotStatus();
        cgds.btn1 = dct.substring(0, 2);
        cgds.sensor1 = dct.substring(2, 4);
        cgds.btn2 = dct.substring(4, 6);
        cgds.sensor2 = dct.substring(6, 8);
        cgds.btn3 = dct.substring(8, 10);
        cgds.sensor3 = dct.substring(10, 12);
        cgds.btn4 = dct.substring(12, 14);
        cgds.sensor4 = dct.substring(14, 16);
        cgds.lock1 = dct.substring(16, 18);
        cgds.lock2 = dct.substring(18, 20);
        cgds.lock3 = dct.substring(20, 22);
        cgds.lock4 = dct.substring(22, 24);
        cgds.door1 = dct.substring(24, 26);
        cgds.door2 = dct.substring(26, 28);
        cgds.door3 = dct.substring(28, 30);
        cgds.door4 = dct.substring(30, 32);
        return cgds;
    }

    public static void main(String[] args) {
        CmdGetDotStatus c = CmdGetDotStatus.parse("01010101010101010101010104040404");
        System.out.println(c);
    }
}
